<template>
  <a-modal title="发送优惠券" :width="800" :maskClosable="false" v-model="visible" @ok="handleOk">
    <a-form :form="form">
      <a-form-item
        label="输入手机号"
        :labelCol="{lg: {span: 7}, sm: {span: 7}}"
        :wrapperCol="{lg: {span: 10}, sm: {span: 17} }"
      >
        <a-textarea
          v-decorator="[
                'phoneNumbers',
                {rules: [{ required: true, message: '输入手机号（多个用,分割）' }]}
              ]"
          placeholder="输入手机号（多个用,分割）最多支持50个手机号"
          :rows="20"
        />
      </a-form-item>
    </a-form>
  </a-modal>
</template>
<script>
import moment from 'moment'
import { apiCouponSend } from '@/api/promotion'

export default {
  name: 'SendCouponModal',
  data() {
    return {
      visible: false,
      coupon: {},
      form: this.$form.createForm(this)
    }
  },
  methods: {
    sendCoupon(record) {
      this.form.resetFields()
      this.coupon = Object.assign({}, record)
      console.log('sendCoupon:', this.coupon)
      this.visible = true
    },
    // handler
    handleOk() {
      const _this = this
      this.form.validateFields((err, values) => {
        if (!err) {
          const phoneNumbers = values.phoneNumbers.split(',')
          const params = {
            couponId: this.coupon.id,
            phoneNumbers: phoneNumbers
          }
          console.log('params: ', params)
          apiCouponSend(params).then(res => {
            if (res.status === 0) {
              _this.$message.success('发送成功')
              this.visible = false
              _this.$emit('ok')
            } else {
              _this.$message.success(res.msg)
            }
          })
        }
      })
    }
  },
  created() {},
  watch: {}
}
</script>
